package com.itheima;

import org.junit.Test;

import java.util.Arrays;

public class Tpoic53 {


    public int maxSubArray(int[] nums) {
        int len = nums.length;
        int[] dp = new int[len + 1];

        dp[0] = nums[0];
        for(int i = 1; i < len; i++) {
            dp[i] = Math.max(nums[i] + dp[i - 1], nums[i]);
        }

        return Arrays.stream(dp).max().getAsInt();
    }

    @Test
    public void test() {
        System.out.println(maxSubArray(new int[] {-2,1,-3,4,-1,2,1,-5,4}));
    }
}
